﻿/*---------------------------------------------------------------*/
//  Requirment: Yahoo-dom-event.js
/*---------------------------------------------------------------*/

function SimpleScroll(containerID)
{
    var defConfig = { delay: 2, speed: 20, startDelay: 2, scrollItemCount: 1 }
    container = document.getElementById(containerID);
    var config = defConfig; var handle = {}; var scrollTimeId = null, pause = false;

    $('#' + containerID).bind('onScroll', function(){
        for (var i = 0; i < config.scrollItemCount; i++) { 
            container.appendChild(container.getElementsByTagName('li')[0]);
        }
    });
    
    var scroll = function() { 
        if (pause) return; 
        container.scrollTop += 2; 
        var lh = config.lineHeight || container.getElementsByTagName('li')[0].offsetHeight; 
        if (container.scrollTop % lh <= 1) { 
            clearInterval(scrollTimeId);
            $('#' + containerID).triggerHandler('onScroll'); 
            container.scrollTop = 0; 
            setTimeout(start, config.delay * 1000); 
        } 
    }
    var start = function()
    {
        var lh = config.lineHeight || container.getElementsByTagName('li')[0].offsetHeight; 
        if (container.scrollHeight - container.offsetHeight >= lh)
            scrollTimeId = setInterval(scroll, config.speed);
    }

    setTimeout(start, config.startDelay * 1000);

    $('#' + containerID).bind('mouseover', function(){pause = true;});
    $('#' + containerID).bind('mouseout', function(){pause = false;});
}